home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / man / cat.3 / libexpect.3 < prev    next >
Encoding:
Text File  |  1995-07-26  |  47.6 KB  |  793 lines

  1.  
  2.  
  3.  
  4.      LLLLIIIIBBBBEEEEXXXXPPPPEEEECCCCTTTT((((3333))))    UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((11112222 DDDDeeeecccceeeemmmmbbbbeeeerrrr 1111999999991111))))     LLLLIIIIBBBBEEEEXXXXPPPPEEEECCCCTTTT((((3333))))
  5.  
  6.  
  7.  
  8.      NNNNAAAAMMMMEEEE
  9.           libexpect - programmed dialogue with interactive programs -
  10.           C functions
  11.  
  12.      DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  13.           This library contains functions that allow Expect to be used
  14.           as a Tcl extension or to be used directly from C or C++
  15.           (without Tcl).  Adding Expect as a Tcl extension is very
  16.           short and simple, so that will be covered first.
  17.  
  18.      SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  19.           ####iiiinnnncccclllluuuuddddeeee eeeexxxxppppeeeecccctttt____ttttccccllll....hhhh
  20.           EEEExxxxpppp____IIIInnnniiiitttt((((iiiinnnntttteeeerrrrpppp))));;;;
  21.  
  22.           cccccccc ffffiiiilllleeeessss............ ----lllleeeexxxxppppeeeecccctttt ----llllttttccccllll ----llllmmmm
  23.  
  24.           The Exp_Init function adds expect commands to the named
  25.           interpreter.  It avoids overwriting commands that already
  26.           exist, however aliases beginning with "exp_" are always
  27.           created for expect commands.  So for example, "send" can be
  28.           used as "exp_send".
  29.  
  30.           Generally, you should only call Expect commands via
  31.           Tcl_Eval.  Certain auxiliary functions may be called
  32.           directly.  They are summarized below.  They may be useful in
  33.           constructing your own main.  Look at the file exp_main_exp.c
  34.           in the Expect distribution as a prototype main.  Another
  35.           prototype is tclAppInit.c in the Tcl source distribution.  A
  36.           prototype for working with Tk is in exp_main_tk.c in the
  37.           Expect distribution.
  38.  
  39.           int exp_cmdlinecmds;
  40.           int exp_interactive;
  41.           FILE *exp_cmdfile;
  42.           char *exp_cmdfilename;
  43.           int exp_tcl_debugger_available;
  44.  
  45.           void exp_parse_argv(Tcl_Interp *,int argc,char **argv);
  46.           int  exp_interpreter(Tcl_Interp *);
  47.           void exp_interpret_cmdfile(Tcl_Interp *,FILE *);
  48.           void exp_interpret_cmdfilename(Tcl_Interp *,char *);
  49.           void exp_interpret_rcfiles(Tcl_Interp *,int my_rc,int sys_rc);
  50.           char *    exp_cook(char *s,int *len);
  51.           void (*exp_app_exit)EXP_PROTO((Tcl_Interp *);
  52.           void exp_exit(Tcl_Interp *,int status);
  53.           void exp_exit_handlers(Tcl_Interp *);
  54.           void exp_error(Tcl_Interp,char *,...);
  55.  
  56.           eeeexxxxpppp____ccccmmmmddddlllliiiinnnneeeeccccmmmmddddssss is 1 if Expect has been invoked with
  57.           commands on the program command-line (using "-c" for
  58.           example).  eeeexxxxpppp____iiiinnnntttteeeerrrraaaaccccttttiiiivvvveeee is 1 if Expect has been invoked
  59.           with the -i flag or if no commands or script is being
  60.  
  61.  
  62.  
  63.      Page 1                                          (printed 7/23/95)
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.      LLLLIIIIBBBBEEEEXXXXPPPPEEEECCCCTTTT((((3333))))    UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((11112222 DDDDeeeecccceeeemmmmbbbbeeeerrrr 1111999999991111))))     LLLLIIIIBBBBEEEEXXXXPPPPEEEECCCCTTTT((((3333))))
  71.  
  72.  
  73.  
  74.           invoked.  eeeexxxxpppp____ccccmmmmddddffffiiiilllleeee is a stream from which Expect will
  75.           read commands.  eeeexxxxpppp____ccccmmmmddddffffiiiilllleeeennnnaaaammmmeeee is the name of a file which
  76.           Expect will open and read commands from.
  77.           eeeexxxxpppp____ttttccccllll____ddddeeeebbbbuuuuggggggggeeeerrrr____aaaavvvvaaaaiiiillllaaaabbbblllleeee is 1 if the debugger has been
  78.           armed.
  79.  
  80.           eeeexxxxpppp____ppppaaaarrrrsssseeee____aaaarrrrggggvvvv reads the representation of the command line.
  81.           Based on what is found, any of the other variables listed
  82.           here are initialized appropriately.  eeeexxxxpppp____iiiinnnntttteeeerrrrpppprrrreeeetttteeeerrrr
  83.           interactively prompts the user for commands and evaluates
  84.           them.  eeeexxxxpppp____iiiinnnntttteeeerrrrpppprrrreeeetttt____ccccmmmmddddffffiiiilllleeee reads the given stream and
  85.           evaluates any commands found.  eeeexxxxpppp____iiiinnnntttteeeerrrrpppprrrreeeetttt____ccccmmmmddddffffiiiilllleeeennnnaaaammmmeeee
  86.           opens the named file and evaluates any commands found.
  87.           eeeexxxxpppp____iiiinnnntttteeeerrrrpppprrrreeeetttt____rrrrccccffffiiiilllleeeessss reads and evalutes the .rc files.  If
  88.           my_rc is zero, then ~/.expectrc is skipped.  If sys_rc is
  89.           zero, then the system-wide expectrc file is skipped.
  90.           eeeexxxxpppp____ccccooooooookkkk returns a static buffer containing the argument
  91.           reproduced with newlines replaced by carriage-return
  92.           linefeed sequences.  The primary purpose of this is to allow
  93.           messages to be produced without worrying about whether the
  94.           terminal is in raw mode or cooked mode.  If length is zero,
  95.           it is computed via strlen.  eeeexxxxpppp____eeeerrrrrrrroooorrrr iiiissss aaaa pppprrrriiiinnnnttttffff----lllliiiikkkkeeee
  96.           ffffuuuunnnnccccttttiiiioooonnnn tttthhhhaaaatttt to interp->result.
  97.  
  98.      SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  99.           ####iiiinnnncccclllluuuuddddeeee <<<<eeeexxxxppppeeeecccctttt....hhhh>>>>
  100.  
  101.           iiiinnnntttt
  102.           eeeexxxxpppp____ssssppppaaaawwwwnnnnllll((((ffffiiiilllleeee,,,, aaaarrrrgggg0000 [[[[,,,, aaaarrrrgggg1111,,,, ............,,,, aaaarrrrggggnnnn]]]] ((((cccchhhhaaaarrrr ****))))0000))));;;;
  103.           cccchhhhaaaarrrr ****ffffiiiilllleeee;;;;
  104.           cccchhhhaaaarrrr ****aaaarrrrgggg0000,,,, ****aaaarrrrgggg1111,,,, ............ ****aaaarrrrggggnnnn;;;;
  105.  
  106.           iiiinnnntttt
  107.           eeeexxxxpppp____ssssppppaaaawwwwnnnnvvvv((((ffffiiiilllleeee,,,,aaaarrrrggggvvvv))));;;;
  108.           cccchhhhaaaarrrr ****ffffiiiilllleeee,,,, ****aaaarrrrggggvvvv[[[[ ]]]];;;;
  109.  
  110.           FFFFIIIILLLLEEEE ****
  111.           eeeexxxxpppp____ppppooooppppeeeennnn((((ccccoooommmmmmmmaaaannnndddd))));;;;
  112.           cccchhhhaaaarrrr ****ccccoooommmmmmmmaaaannnndddd;;;;
  113.  
  114.           eeeexxxxtttteeeerrrrnnnn iiiinnnntttt eeeexxxxpppp____ppppiiiidddd;;;;
  115.           eeeexxxxtttteeeerrrrnnnn iiiinnnntttt eeeexxxxpppp____ttttttttyyyyiiiinnnniiiitttt;;;;
  116.           eeeexxxxtttteeeerrrrnnnn iiiinnnntttt eeeexxxxpppp____ttttttttyyyyccccooooppppyyyy;;;;
  117.           eeeexxxxtttteeeerrrrnnnn iiiinnnntttt eeeexxxxpppp____ccccoooonnnnssssoooolllleeee;;;;
  118.           eeeexxxxtttteeeerrrrnnnn cccchhhhaaaarrrr ****eeeexxxxpppp____ssssttttttttyyyy____iiiinnnniiiitttt;;;;
  119.           eeeexxxxtttteeeerrrrnnnn vvvvooooiiiidddd ((((****eeeexxxxpppp____cccclllloooosssseeee____iiiinnnn____cccchhhhiiiilllldddd))))(((())));;;;
  120.           eeeexxxxtttteeeerrrrnnnn vvvvooooiiiidddd ((((****eeeexxxxpppp____cccchhhhiiiilllldddd____eeeexxxxeeeecccc____pppprrrreeeelllluuuuddddeeee))))(((())));;;;
  121.           eeeexxxxtttteeeerrrrnnnn vvvvooooiiiidddd eeeexxxxpppp____cccclllloooosssseeee____ttttccccllll____ffffiiiilllleeeessss(((())));;;;
  122.  
  123.           cccccccc ffffiiiilllleeeessss............ ----lllleeeexxxxppppeeeecccctttt ----llllttttccccllll ----llllmmmm
  124.  
  125.  
  126.  
  127.  
  128.  
  129.      Page 2                                          (printed 7/23/95)
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.      LLLLIIIIBBBBEEEEXXXXPPPPEEEECCCCTTTT((((3333))))    UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((11112222 DDDDeeeecccceeeemmmmbbbbeeeerrrr 1111999999991111))))     LLLLIIIIBBBBEEEEXXXXPPPPEEEECCCCTTTT((((3333))))
  137.  
  138.  
  139.  
  140.      DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  141.           eeeexxxxpppp____ssssppppaaaawwwwnnnnllll and eeeexxxxpppp____ssssppppaaaawwwwnnnnvvvv fork a new process so that its
  142.           stdin, stdout, and stderr can be written and read by the
  143.           current process.  _f_i_l_e is the name of a file to be executed.
  144.           The _a_r_g pointers are null-terminated strings.  Following the
  145.           style of execve(), _a_r_g_0 (or _a_r_g_v[_0]) is customarily a
  146.           duplicate of the name of the file.
  147.  
  148.           Three interfaces are available, eeeexxxxpppp____ssssppppaaaawwwwnnnnllll is useful when
  149.           the number of arguments is known at compile time.
  150.           eeeexxxxpppp____ssssppppaaaawwwwnnnnvvvv is useful when the number of arguments is not
  151.           known at compile time.  eeeexxxxpppp____ppppooooppppeeeennnn is explained later on.
  152.  
  153.           If the process is successfully created, a file descriptor is
  154.           returned which corresponds to the process's stdin, stdout
  155.           and stderr.  A stream may be associated with the file
  156.           descriptor by using fdopen().  (This should almost certainly
  157.           be followed by setbuf() to unbuffer the I/O.)
  158.  
  159.           Closing the file descriptor will typically be detected by
  160.           the process as an EOF.  Once such a process exits, it should
  161.           be waited upon (via wait) in order to free up the kernel
  162.           process slot.  (Some systems allow you to avoid this if you
  163.           ignore the SIGCHLD signal).
  164.  
  165.           eeeexxxxpppp____ppppooooppppeeeennnn is yet another interface, styled after popen().
  166.           It takes a Bourne shell command line, and returns a stream
  167.           that corresponds to the process's stdin, stdout and stderr.
  168.           The actual implementation of eeeexxxxpppp____ppppooooppppeeeennnn below demonstrates
  169.           eeeexxxxpppp____ssssppppaaaawwwwnnnnllll.
  170.  
  171.           FILE *
  172.           exp_popen(program)
  173.           char *program;
  174.           {
  175.                FILE *fp;
  176.                int ec;
  177.  
  178.                if (0 > (ec = exp_spawnl("sh","sh","-c",program,(char *)0)))
  179.                     return(0);
  180.                if (NULL == (fp = fdopen(ec,"r+")) return(0);
  181.                setbuf(fp,(char *)0);
  182.                return(fp);
  183.           }
  184.  
  185.           After a process is started, the variable eeeexxxxpppp____ppppiiiidddd is set to
  186.           the process-id of the new process.  The variable
  187.           eeeexxxxpppp____ppppttttyyyy____ssssllllaaaavvvveeee____nnnnaaaammmmeeee is set to the name of the slave side of
  188.           the pty.
  189.  
  190.           The spawn functions uses a pty to communicate with the
  191.           process.  By default, the pty is initialized the same way as
  192.  
  193.  
  194.  
  195.      Page 3                                          (printed 7/23/95)
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.      LLLLIIIIBBBBEEEEXXXXPPPPEEEECCCCTTTT((((3333))))    UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((11112222 DDDDeeeecccceeeemmmmbbbbeeeerrrr 1111999999991111))))     LLLLIIIIBBBBEEEEXXXXPPPPEEEECCCCTTTT((((3333))))
  203.  
  204.  
  205.  
  206.           the user's tty (if possible, i.e., if the environment has a
  207.           controlling terminal.)  This initialization can be skipped
  208.           by setting exp_ttycopy to 0.
  209.  
  210.           The pty is further initialized to some system wide defaults
  211.           if exp_ttyinit is non-zero.  The default is generally
  212.           comparable to "stty sane".
  213.  
  214.           The tty setting can be further modified by setting the
  215.           variable eeeexxxxpppp____ssssttttttttyyyy____iiiinnnniiiitttt.  This variable is interpreted in the
  216.           style of stty arguments.  For example, exp_stty_init =
  217.           "sane"; repeats the default initialization.
  218.  
  219.           On some systems, it is possible to redirect console output
  220.           to ptys.  If this is supported, you can force the next spawn
  221.           to obtain the console output by setting the variable
  222.           eeeexxxxpppp____ccccoooonnnnssssoooolllleeee to 1.
  223.  
  224.           Between the time a process is started and the new program is
  225.           given control, the spawn functions can clean up the
  226.           environment by closing file descriptors.  By default, the
  227.           only file descriptors closed ones internal to Expect and any
  228.           marked "close-on-exec".
  229.  
  230.           If needed, you can close additional file descriptors by
  231.           creating an appropriate function and assigning it to
  232.           exp_close_in_child.  The function will be called after the
  233.           fork and before the exec.  (This also modifies the behavior
  234.           of the spawn command in Expect.)
  235.  
  236.           If you are also using Tcl, it may be convenient to use the
  237.           function exp_close_tcl_files which closes all files between
  238.           the default standard file descriptors and the highest
  239.           descriptor known to Tcl.  (Expect does this.)
  240.  
  241.           The function exp_child_exec_prelude is the last function
  242.           called prior to the actual exec in the child.  You can
  243.           redefine this for effects such as manipulating the uid or
  244.           the signals.
  245.  
  246.  
  247.      IIIIFFFF YYYYOOOOUUUU WWWWAAAANNNNTTTT TTTTOOOO AAAALLLLLLLLOOOOCCCCAAAATTTTEEEE YYYYOOOOUUUURRRR OOOOWWWWNNNN PPPPTTTTYYYY
  248.           eeeexxxxtttteeeerrrrnnnn iiiinnnntttt eeeexxxxpppp____aaaauuuuttttooooaaaallllllllooooccccppppttttyyyy;;;;
  249.           eeeexxxxtttteeeerrrrnnnn iiiinnnntttt eeeexxxxpppp____ppppttttyyyy[[[[2222]]]];;;;
  250.  
  251.           The spawn functions use a pty to communicate with the
  252.           process.  By default, a pty is automatically allocated each
  253.           time a process is spawned.  If you want to allocate ptys
  254.           yourself, before calling one of the spawn functions, set
  255.           eeeexxxxpppp____aaaauuuuttttooooaaaallllllllooooccccppppttttyyyy to 0, eeeexxxxpppp____ppppttttyyyy[[[[0000]]]] to the master pty file
  256.           descriptor and eeeexxxxpppp____ppppttttyyyy[[[[1111]]]] to the slave pty file descriptor.
  257.           The expect library will not do any pty initializations
  258.  
  259.  
  260.  
  261.      Page 4                                          (printed 7/23/95)
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.      LLLLIIIIBBBBEEEEXXXXPPPPEEEECCCCTTTT((((3333))))    UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((11112222 DDDDeeeecccceeeemmmmbbbbeeeerrrr 1111999999991111))))     LLLLIIIIBBBBEEEEXXXXPPPPEEEECCCCTTTT((((3333))))
  269.  
  270.  
  271.  
  272.           (e.g., exp_stty_init will not be used).  The slave pty file
  273.           descriptor will be automatically closed when the process is
  274.           spawned.  After the process is started, all further
  275.           communication takes place with the master pty file
  276.           descriptor.
  277.  
  278.           eeeexxxxpppp____ssssppppaaaawwwwnnnnllll and eeeexxxxpppp____ssssppppaaaawwwwnnnnvvvv duplicate the shell's actions in
  279.           searching for an executable file in a list of directories.
  280.           The directory list is obtained from the environment.
  281.  
  282.      EEEEXXXXPPPPEEEECCCCTTTT PPPPRRRROOOOCCCCEEEESSSSSSSSIIIINNNNGGGG
  283.           While it is possible to use read() to read information from
  284.           a process spawned by eeeexxxxpppp____ssssppppaaaawwwwnnnnllll or eeeexxxxpppp____ssssppppaaaawwwwnnnnvvvv, more
  285.           convenient functions are provided.  They are as follows:
  286.  
  287.           iiiinnnntttt
  288.           eeeexxxxpppp____eeeexxxxppppeeeeccccttttllll((((ffffdddd,,,,ttttyyyyppppeeee1111,,,,ppppaaaatttttttteeeerrrrnnnn1111,,,,[[[[rrrreeee1111,,,,]]]],,,,vvvvaaaalllluuuueeee1111,,,,ttttyyyyppppeeee2222,,,,............,,,,eeeexxxxpppp____eeeennnndddd))));;;;
  289.           iiiinnnntttt ffffdddd;;;;
  290.           eeeennnnuuuummmm eeeexxxxpppp____ttttyyyyppppeeee ttttyyyyppppeeee;;;;
  291.           cccchhhhaaaarrrr ****ppppaaaatttttttteeeerrrrnnnn1111,,,, ****ppppaaaatttttttteeeerrrrnnnn2222,,,, ............;;;;
  292.           rrrreeeeggggeeeexxxxpppp ****rrrreeee1111,,,, ****rrrreeee2222,,,, ............;;;;
  293.           iiiinnnntttt vvvvaaaalllluuuueeee1111,,,, vvvvaaaalllluuuueeee2222,,,, ............;;;;
  294.  
  295.           iiiinnnntttt
  296.           eeeexxxxpppp____ffffeeeexxxxppppeeeeccccttttllll((((ffffpppp,,,,ttttyyyyppppeeee1111,,,,ppppaaaatttttttteeeerrrrnnnn1111,,,,[[[[rrrreeee1111,,,,]]]]vvvvaaaalllluuuueeee1111,,,,ttttyyyyppppeeee2222,,,,............,,,,eeeexxxxpppp____eeeennnndddd))));;;;
  297.           FFFFIIIILLLLEEEE ****ffffpppp;;;;
  298.           eeeennnnuuuummmm eeeexxxxpppp____ttttyyyyppppeeee ttttyyyyppppeeee;;;;
  299.           cccchhhhaaaarrrr ****ppppaaaatttttttteeeerrrrnnnn1111,,,, ****ppppaaaatttttttteeeerrrrnnnn2222,,,, ............;;;;
  300.           rrrreeeeggggeeeexxxxpppp ****rrrreeee1111,,,, ****rrrreeee2222,,,, ............;;;;
  301.           iiiinnnntttt vvvvaaaalllluuuueeee1111,,,, vvvvaaaalllluuuueeee2222,,,, ............;;;;
  302.  
  303.           eeeennnnuuuummmm eeeexxxxpppp____ttttyyyyppppeeee {{{{
  304.              eeeexxxxpppp____eeeennnndddd,,,,
  305.              eeeexxxxpppp____gggglllloooobbbb,,,,
  306.              eeeexxxxpppp____eeeexxxxaaaacccctttt,,,,
  307.              eeeexxxxpppp____rrrreeeeggggeeeexxxxpppp,,,,
  308.              eeeexxxxpppp____ccccoooommmmppppiiiilllleeeedddd,,,,
  309.              eeeexxxxpppp____nnnnuuuullllllll,,,,
  310.           }}}};;;;
  311.  
  312.           ssssttttrrrruuuucccctttt eeeexxxxpppp____ccccaaaasssseeee {{{{
  313.              cccchhhhaaaarrrr ****ppppaaaatttttttteeeerrrrnnnn;;;;
  314.              rrrreeeeggggeeeexxxxpppp ****rrrreeee;;;;
  315.              eeeennnnuuuummmm eeeexxxxpppp____ttttyyyyppppeeee ttttyyyyppppeeee;;;;
  316.              iiiinnnntttt vvvvaaaalllluuuueeee;;;;
  317.           }}}};;;;
  318.  
  319.           iiiinnnntttt
  320.           eeeexxxxpppp____eeeexxxxppppeeeeccccttttvvvv((((ffffdddd,,,,ccccaaaasssseeeessss))));;;;
  321.           iiiinnnntttt ffffdddd;;;;
  322.           ssssttttrrrruuuucccctttt eeeexxxxpppp____ccccaaaasssseeee ****ccccaaaasssseeeessss;;;;
  323.  
  324.  
  325.  
  326.  
  327.      Page 5                                          (printed 7/23/95)
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.      LLLLIIIIBBBBEEEEXXXXPPPPEEEECCCCTTTT((((3333))))    UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((11112222 DDDDeeeecccceeeemmmmbbbbeeeerrrr 1111999999991111))))     LLLLIIIIBBBBEEEEXXXXPPPPEEEECCCCTTTT((((3333))))
  335.  
  336.  
  337.  
  338.           iiiinnnntttt
  339.           eeeexxxxpppp____ffffeeeexxxxppppeeeeccccttttvvvv((((ffffpppp,,,,ccccaaaasssseeeessss))));;;;
  340.           FFFFIIIILLLLEEEE ****ffffpppp;;;;
  341.           ssssttttrrrruuuucccctttt eeeexxxxpppp____ccccaaaasssseeee ****ccccaaaasssseeeessss;;;;
  342.  
  343.           eeeexxxxtttteeeerrrrnnnn iiiinnnntttt eeeexxxxpppp____ttttiiiimmmmeeeeoooouuuutttt;;;;
  344.           eeeexxxxtttteeeerrrrnnnn cccchhhhaaaarrrr ****eeeexxxxpppp____mmmmaaaattttcccchhhh;;;;
  345.           eeeexxxxtttteeeerrrrnnnn cccchhhhaaaarrrr ****eeeexxxxpppp____mmmmaaaattttcccchhhh____eeeennnndddd;;;;
  346.           eeeexxxxtttteeeerrrrnnnn cccchhhhaaaarrrr ****eeeexxxxpppp____bbbbuuuuffffffffeeeerrrr;;;;
  347.           eeeexxxxtttteeeerrrrnnnn cccchhhhaaaarrrr ****eeeexxxxpppp____bbbbuuuuffffffffeeeerrrr____eeeennnndddd;;;;
  348.           eeeexxxxtttteeeerrrrnnnn iiiinnnntttt eeeexxxxpppp____mmmmaaaattttcccchhhh____mmmmaaaaxxxx;;;;
  349.           eeeexxxxtttteeeerrrrnnnn iiiinnnntttt eeeexxxxpppp____ffffuuuullllllll____bbbbuuuuffffffffeeeerrrr;;;;
  350.           eeeexxxxtttteeeerrrrnnnn iiiinnnntttt eeeexxxxpppp____rrrreeeemmmmoooovvvveeee____nnnnuuuullllllllssss;;;;
  351.  
  352.           The functions wait until the output from a process matches
  353.           one of the patterns, a specified time period has passed, or
  354.           an EOF is seen.
  355.  
  356.           The first argument to each function is either a file
  357.           descriptor or a stream.  Successive sets of arguments
  358.           describe patterns and associated integer values to return
  359.           when the pattern matches.
  360.  
  361.           The type argument is one of four values.  exp_end indicates
  362.           that no more patterns appear.  exp_glob indicates that the
  363.           pattern is a glob-style string pattern.  exp_exact indicates
  364.           that the pattern is an exact string.  exp_regexp indicates
  365.           that the pattern is a regexp-style string pattern.
  366.           exp_compiled indicates that the pattern is a regexp-style
  367.           string pattern, and that its compiled form is also provided.
  368.           exp_null indicates that the pattern is a null (for debugging
  369.           purposes, a string pattern must also follow - for debugging
  370.           purposes).
  371.  
  372.           If the compiled form is not provided with the functions
  373.           eeeexxxxpppp____eeeexxxxppppeeeeccccttttllll and eeeexxxxpppp____ffffeeeexxxxppppeeeeccccttttllll, , any pattern compilation done
  374.           internally is thrown away after the function returns.  The
  375.           functions eeeexxxxpppp____eeeexxxxppppeeeeccccttttvvvv and eeeexxxxpppp____ffffeeeexxxxppppeeeeccccttttvvvv will automatically
  376.           compile patterns and will not throw them away.  Instead,
  377.           they must be discarded by the user, by calling free on each
  378.           pattern.  It is only necessary to discard them, the last
  379.           time the cases are used.
  380.  
  381.           Regexp subpatterns matched are stored in the compiled
  382.           regexp.  Assuming "re" contains a compiled regexp, the
  383.           matched string can be found in re->startp[0].  The match
  384.           substrings (according to the parentheses) in the original
  385.           pattern can be found in re->startp[1], re->startp[2], and so
  386.           on, up to re->startp[9].  The corresponding strings ends are
  387.           re->endp[x] where x is that same index as for the string
  388.           start.
  389.  
  390.  
  391.  
  392.  
  393.      Page 6                                          (printed 7/23/95)
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.      LLLLIIIIBBBBEEEEXXXXPPPPEEEECCCCTTTT((((3333))))    UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((11112222 DDDDeeeecccceeeemmmmbbbbeeeerrrr 1111999999991111))))     LLLLIIIIBBBBEEEEXXXXPPPPEEEECCCCTTTT((((3333))))
  401.  
  402.  
  403.  
  404.           The type exp_null matches if a null appears in the input.
  405.           The variable exp_remove_nulls must be set to 0 to prevent
  406.           nulls from being automatically stripped.  By default,
  407.           exp_remove_nulls is set to 1 and nulls are automatically
  408.           stripped.
  409.  
  410.           eeeexxxxpppp____eeeexxxxppppeeeeccccttttvvvv and eeeexxxxpppp____ffffeeeexxxxppppeeeeccccttttvvvv are useful when the number of
  411.           patterns is not known in advance.  In this case, the sets
  412.           are provided in an array.  The end of the array is denoted
  413.           by a struct exp_case with type exp_end.  For the rest of
  414.           this discussion, these functions will be referred to
  415.           generically as _e_x_p_e_c_t.
  416.  
  417.           If a pattern matches, then the corresponding integer value
  418.           is returned.  Values need not be unique, however they should
  419.           be positive to avoid being mistaken for EXP_EOF,
  420.           EXP_TIMEOUT, or EXP_FULLBUFFER.  Upon EOF or timeout, the
  421.           value EEEEXXXXPPPP____EEEEOOOOFFFF or EEEEXXXXPPPP____TTTTIIIIMMMMEEEEOOOOUUUUTTTT is returned.  The default
  422.           timeout period is 10 seconds but may be changed by setting
  423.           the variable eeeexxxxpppp____ttttiiiimmmmeeeeoooouuuutttt.  A value of -1 disables a timeout
  424.           from occurring.  A value of 0 causes the expect function to
  425.           return immediately (i.e., poll) after one read().  However
  426.           it must be preceded by a function such as select, poll, or
  427.           an event manager callback to guarantee that there is data to
  428.           be read.
  429.  
  430.           If the variable exp_full_buffer is 1, then EXP_FULLBUFFER is
  431.           returned if exp_buffer fills with no pattern having matched.
  432.  
  433.           When the expect function returns, eeeexxxxpppp____bbbbuuuuffffffffeeeerrrr points to the
  434.           buffer of characters that was being considered for matching.
  435.           eeeexxxxpppp____bbbbuuuuffffffffeeeerrrr____eeeennnndddd ppppooooiiiinnnnttttssss ttttoooo oooonnnneeee ppppaaaasssstttt tttthhhheeee If a match occurred,
  436.           eeeexxxxpppp____mmmmaaaattttcccchhhh points into eeeexxxxpppp____bbbbuuuuffffffffeeeerrrr where the match began.
  437.           eeeexxxxpppp____mmmmaaaattttcccchhhh____eeeennnndddd points to one character past where the match
  438.           ended.
  439.  
  440.           Each time new input arrives, it is compared to each pattern
  441.           in the order they are listed.  Thus, you may test for
  442.           absence of a match by making the last pattern something
  443.           guaranteed to appear, such as a prompt.  In situations where
  444.           there is no prompt, you must check for EEEEXXXXPPPP____TTTTIIIIMMMMEEEEOOOOUUUUTTTT (just
  445.           like you would if you were interacting manually).  More
  446.           philosophy and strategies on specifying eeeexxxxppppeeeecccctttt patterns can
  447.           be found in the documentation on the eeeexxxxppppeeeecccctttt program, itself.
  448.           See SEE ALSO below.
  449.  
  450.           Patterns are the usual C-shell-style regular expressions.
  451.           For example, the following fragment looks for a successful
  452.           login, such as from a telnet dialogue.
  453.  
  454.                switch (exp_expectl(
  455.                     exp_glob,"connected",CONN,
  456.  
  457.  
  458.  
  459.      Page 7                                          (printed 7/23/95)
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.      LLLLIIIIBBBBEEEEXXXXPPPPEEEECCCCTTTT((((3333))))    UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((11112222 DDDDeeeecccceeeemmmmbbbbeeeerrrr 1111999999991111))))     LLLLIIIIBBBBEEEEXXXXPPPPEEEECCCCTTTT((((3333))))
  467.  
  468.  
  469.  
  470.                     exp_glob,"busy",BUSY,
  471.                     exp_glob,"failed",ABORT,
  472.                     exp_glob,"invalid password",ABORT,
  473.                     exp_end)) {
  474.                case CONN:     /* logged in successfully */
  475.                     break;
  476.                case BUSY:     /* couldn't log in at the moment */
  477.                     break;
  478.                case EXP_TIMEOUT:
  479.                case ABORT:    /* can't log in at any moment! */
  480.                     break;
  481.                default: /* problem with expect */
  482.                }
  483.  
  484.           Asterisks (as in the example above) are a useful shorthand
  485.           for omitting line-termination characters and other detail.
  486.           Patterns must match the entire output of the current process
  487.           (since the previous read on the descriptor or stream). More
  488.           than 2000 bytes of output can force earlier bytes to be
  489.           "forgotten".  This may be changed by setting the variable
  490.           eeeexxxxpppp____mmmmaaaattttcccchhhh____mmmmaaaaxxxx.  Note that excessively large values can slow
  491.           down the pattern matcher.
  492.  
  493.      RRRRUUUUNNNNNNNNIIIINNNNGGGG IIIINNNN TTTTHHHHEEEE BBBBAAAACCCCKKKKGGGGRRRROOOOUUUUNNNNDDDD
  494.           eeeexxxxtttteeeerrrrnnnn iiiinnnntttt eeeexxxxpppp____ddddiiiissssccccoooonnnnnnnneeeecccctttteeeedddd;;;;
  495.           iiiinnnntttt eeeexxxxpppp____ddddiiiissssccccoooonnnnnnnneeeecccctttt(((())));;;;
  496.  
  497.           It is possible to move a process into the background after
  498.           it has begun running.  A typical use for this is to read
  499.           passwords and then go into the background to sleep before
  500.           using the passwords to do real work.
  501.  
  502.           To move a process into the background, fork, call
  503.           exp_disconnect() in the child process and exit() in the
  504.           parent process.  This disassociates your process from the
  505.           controlling terminal.  If you wish to move a process into
  506.           the background in a different way, you must set the variable
  507.           exp_disconnected to 1.  This allows processes spawned after
  508.           this point to be started correctly.
  509.  
  510.      MMMMUUUULLLLTTTTIIIIPPPPLLLLEEEEXXXXIIIINNNNGGGG
  511.           By default, the expect functions block inside of a read on a
  512.           single file descriptor.  If you want to wait on patterns
  513.           from multiple file descriptors, use select, poll, or an
  514.           event manager.  They will tell you what file descriptor is
  515.           ready to read.
  516.  
  517.           When a file descriptor is ready to read, you can use the
  518.           expect functions to do one and only read by setting timeout
  519.           to 0.
  520.  
  521.      SSSSLLLLAAAAVVVVEEEE CCCCOOOONNNNTTTTRRRROOOOLLLL
  522.  
  523.  
  524.  
  525.      PPPPaaaaggggeeee 8888                                          ((((pppprrrriiiinnnntttteeeedddd 7777////22223333////99995555))))
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.      LLLLIIIIBBBBEEEEXXXXPPPPEEEECCCCTTTT((((3333))))    UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((11112222 DDDDeeeecccceeeemmmmbbbbeeeerrrr 1111999999991111))))     LLLLIIIIBBBBEEEEXXXXPPPPEEEECCCCTTTT((((3333))))
  533.  
  534.  
  535.  
  536.           vvvvooooiiiidddd
  537.           eeeexxxxpppp____ssssllllaaaavvvveeee____ccccoooonnnnttttrrrroooollll((((ffffdddd,,,,eeeennnnaaaabbbblllleeee))))
  538.           iiiinnnntttt ffffdddd;;;;
  539.           iiiinnnntttt eeeennnnaaaabbbblllleeee;;;;
  540.  
  541.  
  542.           Pty trapping is normally done automatically by the expect
  543.           functions.  However, if you want to issue an ioctl, for
  544.           example, directly on the slave device, you should temporary
  545.           disable trapping.
  546.  
  547.           Pty trapping can be controlled with exp_slave_control.  The
  548.           first argument is the file descriptor corresponding to the
  549.           spawned process.  The second argument is a 0 if trapping is
  550.           to be disabled and 1 if it is to be enabled.
  551.  
  552.  
  553.      EEEERRRRRRRROOOORRRRSSSS
  554.           All functions indicate errors by returning -1 and setting
  555.           errno.
  556.  
  557.           Errors that occur after the spawn functions fork (e.g.,
  558.           attempting to spawn a non-existent program) are written to
  559.           the process's stderr, and will be read by the first eeeexxxxppppeeeecccctttt.
  560.  
  561.      SSSSIIIIGGGGNNNNAAAALLLLSSSS
  562.           eeeexxxxtttteeeerrrrnnnn iiiinnnntttt eeeexxxxpppp____rrrreeeeaaaaddddiiiinnnngggg;;;;
  563.           eeeexxxxtttteeeerrrrnnnn jjjjmmmmpppp____bbbbuuuuffff eeeexxxxpppp____rrrreeeeaaaaddddeeeennnnvvvv;;;;
  564.  
  565.           eeeexxxxppppeeeecccctttt uses alarm() to timeout, thus if you generate alarms
  566.           during eeeexxxxppppeeeecccctttt, it will timeout prematurely.
  567.  
  568.           Internally, eeeexxxxppppeeeecccctttt calls read() which can be interrupted by
  569.           signals.  If you define signal handlers, you can choose to
  570.           restart or abort eeeexxxxppppeeeecccctttt's internal read.  The variable,
  571.           eeeexxxxpppp____rrrreeeeaaaaddddiiiinnnngggg, is true iff eeeexxxxppppeeeecccctttt's read has been interrupted.
  572.           longjmp(exp_readenv,EXP_ABORT) will abort the read.
  573.           longjmp(exp_readenv,EXP_RESTART) will restart the read.
  574.  
  575.      LLLLOOOOGGGGGGGGIIIINNNNGGGG
  576.           eeeexxxxtttteeeerrrrnnnn iiiinnnntttt eeeexxxxpppp____lllloooogggguuuusssseeeerrrr;;;;
  577.           eeeexxxxtttteeeerrrrnnnn iiiinnnntttt eeeexxxxpppp____llllooooggggffffiiiilllleeee____aaaallllllll
  578.           eeeexxxxtttteeeerrrrnnnn FFFFIIIILLLLEEEE ****eeeexxxxpppp____llllooooggggffffiiiilllleeee;;;;
  579.  
  580.           If eeeexxxxpppp____lllloooogggguuuusssseeeerrrr is nonzero, eeeexxxxppppeeeecccctttt sends any output from the
  581.           spawned process to stdout.  Since interactive programs
  582.           typically echo their input, this usually suffices to show
  583.           both sides of the conversation.  If eeeexxxxpppp____llllooooggggffffiiiilllleeee is also
  584.           nonzero, this same output is written to the stream defined
  585.           by eeeexxxxpppp____llllooooggggffffiiiilllleeee.  If eeeexxxxpppp____llllooooggggffffiiiilllleeee____aaaallllllll is non-zero, eeeexxxxpppp____llllooooggggffffiiiilllleeee
  586.           is written regardless of the value of eeeexxxxpppp____lllloooogggguuuusssseeeerrrr.
  587.  
  588.  
  589.  
  590.  
  591.      Page 9                                          (printed 7/23/95)
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598.      LLLLIIIIBBBBEEEEXXXXPPPPEEEECCCCTTTT((((3333))))    UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((11112222 DDDDeeeecccceeeemmmmbbbbeeeerrrr 1111999999991111))))     LLLLIIIIBBBBEEEEXXXXPPPPEEEECCCCTTTT((((3333))))
  599.  
  600.  
  601.  
  602.      DDDDEEEEBBBBUUUUGGGGGGGGIIIINNNNGGGG
  603.           While I consider the library to be easy to use, I think that
  604.           the standalone expect program is much, much, easier to use
  605.           than working with the C compiler and its usual edit,
  606.           compile, debug cycle.  Unlike typical C programs, most of
  607.           the debugging isn't getting the C compiler to accept your
  608.           programs - rather, it is getting the dialogue correct.
  609.           Also, translating scripts from expect to C is usually not
  610.           necessary.  For example, the speed of interactive dialogues
  611.           is virtually never an issue.  So please try the standalone
  612.           'expect' program first.  I suspect it is a more appropriate
  613.           solution for most people than the library.
  614.  
  615.           Nonetheless, if you feel compelled to debug in C, here are
  616.           some tools to help you.
  617.  
  618.           eeeexxxxtttteeeerrrrnnnn iiiinnnntttt eeeexxxxpppp____iiiissss____ddddeeeebbbbuuuuggggggggiiiinnnngggg;;;;
  619.           eeeexxxxtttteeeerrrrnnnn FFFFIIIILLLLEEEE ****eeeexxxxpppp____ddddeeeebbbbuuuuggggffffiiiilllleeee;;;;
  620.  
  621.           While expect dialogues seem very intuitive, trying to codify
  622.           them in a program can reveal many surprises in a program's
  623.           interface.  Therefore a variety of debugging aids are
  624.           available.  They are controlled by the above variables, all
  625.           0 by default.
  626.  
  627.           Debugging information internal to eeeexxxxppppeeeecccctttt is sent to stderr
  628.           when eeeexxxxpppp____iiiissss____ddddeeeebbbbuuuuggggggggiiiinnnngggg is non-zero.  The debugging
  629.           information includes every character received, and every
  630.           attempt made to match the current input against the
  631.           patterns.  In addition, non-printable characters are
  632.           translated to a printable form.  For example, a control-C
  633.           appears as a caret followed by a C.  If eeeexxxxpppp____llllooooggggffffiiiilllleeee is non-
  634.           zero, this information is also written to that stream.
  635.  
  636.           If eeeexxxxpppp____ddddeeeebbbbuuuuggggffffiiiilllleeee is non-zero, all normal and debugging
  637.           information is written to that stream, regardless of the
  638.           value of eeeexxxxpppp____iiiissss____ddddeeeebbbbuuuuggggggggiiiinnnngggg.
  639.  
  640.      CCCCAAAAVVVVEEEEAAAATTTTSSSS
  641.           The stream versions of the eeeexxxxppppeeeecccctttt functions are much slower
  642.           than the file descriptor versions because there is no way to
  643.           portably read an unknown number of bytes without the
  644.           potential of timing out.  Thus, characters are read one at a
  645.           time.  You are therefore strongly encouraged to use the file
  646.           descriptor versions of eeeexxxxppppeeeecccctttt (although, automated versions
  647.           of interactive programs don't usually demand high speed
  648.           anyway).
  649.  
  650.           You can actually get the best of both worlds, writing with
  651.           the usual stream functions and reading with the file
  652.           descriptor versions of eeeexxxxppppeeeecccctttt as long as you don't attempt
  653.           to intermix other stream input functions (e.g., fgetc).  To
  654.  
  655.  
  656.  
  657.      Page 10                                         (printed 7/23/95)
  658.  
  659.  
  660.  
  661.  
  662.  
  663.  
  664.      LLLLIIIIBBBBEEEEXXXXPPPPEEEECCCCTTTT((((3333))))    UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((11112222 DDDDeeeecccceeeemmmmbbbbeeeerrrr 1111999999991111))))     LLLLIIIIBBBBEEEEXXXXPPPPEEEECCCCTTTT((((3333))))
  665.  
  666.  
  667.  
  668.           do this, pass fileno(stream) as the file descriptor each
  669.           time.  Fortunately, there is little reason to use anything
  670.           but the eeeexxxxppppeeeecccctttt functions when reading from interactive
  671.           programs.
  672.  
  673.           There is no matching exp_pclose to exp_popen (unlike popen
  674.           and pclose).  It only takes two functions to close down a
  675.           connection (fclose() followed by waiting on the pid), but it
  676.           is not uncommon to separate these two actions by large time
  677.           intervals, so the function seems of little value.
  678.  
  679.           If you are running on a Cray running Unicos (all I know for
  680.           sure from experience), you must run your compiled program as
  681.           root or setuid.  The problem is that the Cray only allows
  682.           root processes to open ptys. You should observe as much
  683.           precautions as possible:  If you don't need permissions,
  684.           setuid(0) only immediately before calling one of the spawn
  685.           functions and immediately set it back afterwards.
  686.  
  687.           Normally, ssssppppaaaawwwwnnnn takes little time to execute.  If you notice
  688.           spawn taking a significant amount of time, it is probably
  689.           encountering ptys that are wedged.  A number of tests are
  690.           run on ptys to avoid entanglements with errant processes.
  691.           (These take 10 seconds per wedged pty.)  Running expect with
  692.           the -d option will show if eeeexxxxppppeeeecccctttt is encountering many ptys
  693.           in odd states.  If you cannot kill the processes to which
  694.           these ptys are attached, your only recourse may be to
  695.           reboot.
  696.  
  697.      BBBBUUUUGGGGSSSS
  698.           The eeeexxxxpppp____ffffeeeexxxxppppeeeecccctttt functions don't work at all under HP-UX - it
  699.           appears to be a bug in getc.  Follow the advice (above)
  700.           about using the eeeexxxxpppp____eeeexxxxppppeeeecccctttt functions (which doesn't need to
  701.           call getc).  If you fix the problem (before I do - please
  702.           check the latest release) let me know.
  703.  
  704.      SSSSEEEEEEEE AAAALLLLSSSSOOOO
  705.           An alternative to this library is the eeeexxxxppppeeeecccctttt program.
  706.           eeeexxxxppppeeeecccctttt interprets scripts written in a high-level language
  707.           which direct the dialogue.  In addition, the user can take
  708.           control and interact directly when desired.  If it is not
  709.           absolutely necessary to write your own C program, it is much
  710.           easier to use eeeexxxxppppeeeecccctttt to perform the entire interaction.  It
  711.           is described further in the following references:
  712.  
  713.           "_e_x_p_e_c_t: _C_u_r_i_n_g _T_h_o_s_e _U_n_c_o_n_t_r_o_l_l_a_b_l_e _F_i_t_s _o_f _I_n_t_e_r_a_c_t_i_v_i_t_y"
  714.           by Don Libes, Proceedings of the Summer 1990 USENIX
  715.           Conference, Anaheim, California, June 11-15, 1990.
  716.  
  717.           "_U_s_i_n_g _e_x_p_e_c_t _t_o _A_u_t_o_m_a_t_e _S_y_s_t_e_m _A_d_m_i_n_i_s_t_r_a_t_i_o_n _T_a_s_k_s" by
  718.           Don Libes, Proceedings of the 1990 USENIX Large Installation
  719.           Systems Administration Conference, Colorado Springs,
  720.  
  721.  
  722.  
  723.      Page 11                                         (printed 7/23/95)
  724.  
  725.  
  726.  
  727.  
  728.  
  729.  
  730.      LLLLIIIIBBBBEEEEXXXXPPPPEEEECCCCTTTT((((3333))))    UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((11112222 DDDDeeeecccceeeemmmmbbbbeeeerrrr 1111999999991111))))     LLLLIIIIBBBBEEEEXXXXPPPPEEEECCCCTTTT((((3333))))
  731.  
  732.  
  733.  
  734.           Colorado, October 17-19, 1990.
  735.  
  736.           expect(1), alarm(3), read(2), write(2), fdopen(3),
  737.           execve(2), execvp(3), longjmp(3), pty(4).
  738.  
  739.           There are several examples C programs in the test directory
  740.           of eeeexxxxppppeeeecccctttt's source distribution which use the expect
  741.           library.
  742.  
  743.      AAAAUUUUTTTTHHHHOOOORRRR
  744.           Don Libes, libes@nist.gov, National Institute of Standards
  745.           and Technology
  746.  
  747.      AAAACCCCKKKKNNNNOOOOWWWWLLLLEEEEDDDDGGGGEEEEMMMMEEEENNNNTTTTSSSS
  748.           Thanks to John Ousterhout (UCBerkeley) for supplying the
  749.           pattern matcher.
  750.  
  751.           Design and implementation of the eeeexxxxppppeeeecccctttt library was paid for
  752.           by the U.S. government and is therefore in the public
  753.           domain.  However the author and NIST would like credit if
  754.           this program and documentation or portions of them are used.
  755.  
  756.  
  757.  
  758.  
  759.  
  760.  
  761.  
  762.  
  763.  
  764.  
  765.  
  766.  
  767.  
  768.  
  769.  
  770.  
  771.  
  772.  
  773.  
  774.  
  775.  
  776.  
  777.  
  778.  
  779.  
  780.  
  781.  
  782.  
  783.  
  784.  
  785.  
  786.  
  787.  
  788.  
  789.      Page 12                                         (printed 7/23/95)
  790.  
  791.  
  792.  
  793.